'use strict';
var Mock = require('mockjs')
var Random = Mock.Random;
var fs = require('fs');
//组名
const groupArrays = [

    '台式生产1线配料1组',
    '笔记本生产质检2组',
    '服务器生产测试1组'
];
//部门名称
const deptArrays = [
    'DT制造管理一部',
    'NB制造管理部',
    'SVR制造管理部',
    'SVR制造生产部',
];
//岗位名称
const postNameArray = [
    '条码扫描', '打主板螺钉', '取螺钉/散热片', '装PS2线', '取线缆/螺钉', '喇叭安装', '装主板', '贴系统标签', '锁主板螺丝2', '贴信息标签1', '机箱抱取', '安装主板', '装CPU/内存', '工位1', '装开关线', '安装COM1线缆', '拆机箱盖螺钉'
];
//班次
const shiftNameArray = [
    'CD 白班 09:00--18:00',
    'CD 夜班班 17:30--09:30',
    '早班',
    '中班',
    '晚班'
];
//产品线
const productNameArray = [];
//机型
const modelNameArray = [
    'SB12343',
    'tiny',
    '传统台式（大'
];

const postImportanceNameArray = [
    "是",
    "否"
]

function getProductLine(deptName) {
    var re = /([A-Z]{2,3})/ig;
    var r = re.exec(deptName);
    return r[1]
}
// "userId": "L027515",

module.exports = {
    'GET /api/keypost/list': function(req, res, next) {

        const array = [];

        for (let i = 0; i < 30; i++) {

            var data = Mock.mock({
                "content|5": [{
                    "createTime": Random.date('2022-07-dd') + " 17:05:26",
                    "modifyTime": Random.date('2022-07-dd') + " 14:53:09",
                    "createBy": "SYS",
                    "modifyBy": "SYS",
                    "isDeleted": "0",
                    "tid": Random.string('lower', 64),
                    "tenantId": "1",
                    "deptId": Random.integer(100, 200),
                    "groupId": Random.integer(300, 400),
                    "userId": "L0" + Random.integer(27000, 30000),
                    "userName": Random.cname(),
                    "checkinTime": Random.date('2022-MM-dd') + "09:16:00",
                    "model": modelNameArray[Random.integer(0, modelNameArray.length - 1)],
                    "postName": postNameArray[Random.integer(0, postNameArray.length - 1)],
                    "flag": 1,
                    "shiftName": shiftNameArray[Random.integer(0, shiftNameArray.length - 1)],
                    "status": Random.integer(0, 1),
                    "approveDate": Random.date('2022-MM-dd') + " 16:44:27",
                    "validityDate": Random.date('2022-MM-dd') + " 00:00:00",
                    "approveUsersItCode": Random.string('lower', 5, 10),
                    "hireDate": Random.date('2022-MM-dd') + " 00:00:00",
                    "keyFlag": 0,
                    "groupLeaderName": Random.cname(),
                    "groupLeaderId": "L0" + Random.integer(27000, 30000),
                    "departmentCharge": Random.string('lower', 5, 10),
                    "productLine": "",
                    "deptName": deptArrays[Random.integer(0, deptArrays.length - 1)],
                    "groupName": groupArrays[Random.integer(0, groupArrays.length - 1)],
                    "postImportance": postImportanceNameArray[Random.integer(0, postImportanceNameArray.length - 1)],
                    "workingGroupId": Random.integer(100, 200),
                    "type": 0,
                    "line": 'KIT104',
                    "lastIncumbencyDate": Random.date('2022-MM-dd') + " 00:00:00"


                }]
            });
            array.push(data.content[3]);
        }
        let sqlText = "";
        for (let i = 0; i < array.length; i++) {
            const item = array[i];
            item.productLine = getProductLine(item.deptName);
            if (item.flag === '0') {
                item.keyFlag = '1'
            } else {
                item.keyFlag = '0'
            }
            let sql = "insert into kpc_keypostscerification (tid,tenant_id,create_by,create_time,modify_by,modify_time,is_deleted,dept_id,group_id,user_id,user_name,checkin_time,model,post_name,flag,post_importance,working_group_id,line,type,shift_name,status,approve_date,validity_date,approve_users_it_code,hire_date,last_incumbency_date,key_flag,group_leader_name,group_leader_id,department_charge,product_line,dept_name,group_name)values( " +
                '\'' + item.tid + '\'' + ',' + '\'' + item.tenantId + '\'' + ',' + '\'' + item.createBy + '\'' + ',' + '\'' + item.createTime + '\'' + ',' + '\'' + item.modifyBy + '\'' + ',' + '\'' + item.modifyTime + '\'' + ',' + '\'' + item.isDeleted + '\'' + ',' + '\'' + item.deptId + '\'' + ',' + '\'' + item.groupId + '\'' + ',' + '\'' + item.userId + '\'' + ',' + '\'' + item.userName + '\'' + ',' + '\'' +
                item.checkinTime + '\'' + ',' + '\'' + item.model + '\'' + ',' +
                '\'' + item.postName + '\'' + ',' + '\'' + item.flag + '\'' +
                ',' + '\'' + item.postImportance + '\'' + ',' +
                '\'' + item.workingGroupId + '\'' + ',' + '\'' + item.line +
                '\'' + ',' + '\'' + item.type + '\'' + ',' + '\'' +
                item.shiftName + '\'' + ',' + '\'' + item.status + '\'' + ',' + '\'' + item.approveDate + '\'' + ',' + '\'' + item.validityDate + '\'' + ',' + '\'' +
                item.approveUsersItCode + '\'' + ',' + '\'' + item.hireDate + '\'' +
                ',' + '\'' + item.lastIncumbencyDate + '\'' + ',' + '\'' + item.keyFlag +
                '\'' + ',' + '\'' + item.groupLeaderName + '\'' + ',' + '\'' +
                item.groupLeaderId + '\'' + ',' + '\'' + item.departmentCharge +
                '\'' + ',' + '\'' + item.productLine + '\'' + ',' + '\'' + item.deptName + '\'' + ',' + '\'' + item.groupName + '\'' + ")";
            sqlText += sql + ";";
        }

        setTimeout(function() {
            res.json({ sql: sqlText });
        }, 500);
    },

}